home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
gwuada_9.zip
/
DBX.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-27
|
44KB
|
1,797 lines
/*
* Copyright (C) 1985-1992 New York University
*
* This file is part of the Ada/Ed-C system. See the Ada/Ed README file for
* warranty (none) and distribution info and also the GNU General Public
* License for more details.
*/
/* interface to dbx for sem debugging */
/* interface to dbx for sem debugging */
#include "hdr.h"
#include "libhdr.h"
#include "vars.h"
#include "ifile.h"
#include "setp.h"
#include "arithp.h"
#include "sspansp.h"
#include "chapp.h"
#include "librp.h"
#include "miscp.h"
#include "smiscp.h"
#include "dbxp.h"
#ifndef EXPORT
typedef struct explored
{
short genre; /* discriminant : is explored a node or a symbol ? */
union {
Node n;
Symbol s;
} addr;
} explored;
#define UNDEFINED_STEP 99
#define EXIT_STEP 100
#define NODE_GENRE 0
#define SYMBOL_GENRE 1
int zpadr_opt = 1;
Symbol zsym;
Set zset;
Node znod;
Declaredmap zdcl;
Tuple ztup;
void give_node_reference(Node);
void give_symbol_reference(Symbol);
void zpnodrefa(char *, Node);
void zpset(Set);
void zpsig(Symbol);
void zpsigt();
void zptup(Tuple);
void zpsetsym(Set);
void zpsym(Symbol);
void zpsymrefa(char *, Symbol);
void zpsymref(Symbol);
void zpnodref(Node);
int analyze(char *, explored, int *, int *);
static int adrflag = 1; /* non zero to print address values */
static int stack_ptr = 0;
static explored stack[ 100 ];
static void push(explored);
static explored pop();
static void display_symbol(Symbol);
static void zpcon1(Const);
static void zprat1(Rational);
/*
* The purpose of this program is to provide the one who is not familiar
* with the structure of the AST with a tool which permits him to travel
* from one node to his eventual father or son (we assume that the
* beginning of the exploration will take place at the root of the AST .)
* and focus on the nodes he wants to examine more precisely in a readable
* way .
*/
static void push (explored site) /*;push*/
{
stack [ stack_ptr++ ] = site;
}
static explored pop () /*;pop*/
{
return (stack [ --stack_ptr ]);
}
static void display_symbol(Symbol symbol_explored) /*;display_symbol*/
{
short nature;
system ("clear");
if (symbol_explored == (Symbol)0)
printf ("(Symbol)0\n");
else {
printf("NATURE %s %d \n\n",
nature_str (NATURE (symbol_explored)), symbol_explored);
printf("TYPE_OF %s %d\n",
nature_str(NATURE(TYPE_OF(symbol_explored))),
TYPE_OF(symbol_explored));
printf("ALIAS %s %d\n",
nature_str(NATURE(ALIAS(symbol_explored))), ALIAS(symbol_explored));
printf("SIGNATURE :\n");
if (SIGNATURE (symbol_explored) != ((Tuple)0))
zptup(SIGNATURE (symbol_explored));
else
printf("empty_tuple\n");
if (SCOPE_OF(symbol_explored))
printf("SCOPE_OF %s %d\n",
nature_str(NATURE(SCOPE_OF(symbol_explored))),
SCOPE_OF(symbol_explored));
else
printf("No scope.\n");
printf("OVERLOADS :\n");
if (OVERLOADS (symbol_explored) != ((Tuple)0)) {
nature = NATURE(symbol_explored);
if (nature == na_enum)
printf(" literal map %d\n", OVERLOADS(symbol_explored));
else if (nature == na_package || nature == na_package_spec
|| nature == na_generic_package_spec
|| nature == na_generic_package || nature == na_task_type
|| nature == na_task_obj)
printf(" private declarations %d\n",
OVERLOADS(symbol_explored));
else
display_symbol_list (OVERLOADS (symbol_explored), 1);
}
else
printf ("empty_set\n");
printf("DECLARED %d\n", DECLARED (symbol_explored));
if (ORIG_NAME (symbol_explored) != (char *)0)
printf("ORIG_NAME %s\n", ORIG_NAME (symbol_explored));
printf("SEQ %d\n", S_SEQ (symbol_explored));
printf("UNIT %d\n", S_UNIT (symbol_explored));
printf("TYPE_ATTR %d\n", TYPE_ATTR (symbol_explored));
if (MISC (symbol_explored) != (char *)0)
printf("MISC %s\n", MISC (symbol_explored));
printf("TYPE_KIND %d\n", TYPE_KIND (symbol_explored));
printf("TYPE_SIZE %d\n", TYPE_SIZE (symbol_explored));
if (INIT_PROC(symbol_explored))
printf("INIT_PROC %s %d\n",
nature_str(NATURE(INIT_PROC(symbol_explored))),
INIT_PROC(symbol_explored));
else printf("INIT_PROC = 0\n");
printf("ASSOCIATED_SYMBOLS :\n");
if (ASSOCIATED_SYMBOLS (symbol_explored) != ((Tuple)0))
display_symbol_list (ASSOCIATED_SYMBOLS (symbol_explored), 1);
else
printf ("empty_tuple\n");
printf("SEGMENT %d\n", S_SEGMENT (symbol_explored));
printf("OFFSET %d\n", S_OFFSET (symbol_explored));
printf("\n");
}
}
void display_node(Node node_explored, int list_begin) /*;display_node*/
{
int kind_explored;
system ("clear");
if (node_explored == (Node)0)
printf ("(Node)0\n");
else {
kind_explored = N_KIND (node_explored);
printf ("kind -> %s ", kind_str (kind_explored));
printf ("unit -> %d ", N_UNIT (node_explored));
printf ("side -> %d ", N_SIDE (node_explored));
printf ("overloaded -> %d ", N_OVERLOADED (node_explored));
printf ("sequence -> %d ", N_SEQ (node_explored));
printf ("\n");
printf ("%d", kind_explored);
printf ("\n");
printf ("\n");
/*****************/
/* nu1 component */
/*****************/
printf (" nu1 : ");
if (N_AST1_DEFINED (kind_explored)) {
if (N_AST1(node_explored) != (Node)0)
printf ("AST1 %s \n", kind_str(N_KIND(N_AST1(node_explored))));
else
printf ("AST1 (Node)0 \n");
}
else
printf ("SPAN %d %d \n", N_SPAN0 (node_explored),
N_SPAN1 (node_explored));
printf ("\n");
/*****************/
/* nu2 component */
/*****************/
printf (" nu2 : ");
if (N_AST2_DEFINED (kind_explored)) {
if (N_AST2(node_explored) != (Node)0)
printf ("AST2 %s \n",
kind_str(N_KIND(N_AST2(node_explored))));
else
printf ("AST2 (Node)0 \n");
}
else if (N_LIST_DEFINED (kind_explored)) {
printf ("LIST ");
if (N_LIST (node_explored) != ((Tuple)0))
display_node_list (N_LIST (node_explored), list_begin);
else
printf ("empty_tuple\n");
}
else { /* (N_VAL_DEFINED (kind_explored) */
display_value (node_explored);
printf ("\n");
}
printf ("\n");
/*****************/
/* nu3 component */
/*****************/
printf (" nu3 : ");
if (N_AST3_DEFINED (kind_explored)) {
if (N_AST3(node_explored) != (Node)0)
printf ("AST3 %s \n", kind_str(N_KIND(N_AST3(node_explored))));
else
printf ("AST3 (Node)0 \n");
}
else if (N_UNQ_DEFINED (kind_explored))
printf ("Symbol unq --> %s \n",
nature_str(NATURE(N_UNQ(node_explored))));
else {
printf ("N_NAMES ");
if (N_NAMES (node_explored) != ((Set)0))
display_node_list((Tuple)N_NAMES(node_explored), list_begin);
else
printf ("empty_set\n");
}
printf ("\n");
/*****************/
/* nu4 component */
/*****************/
printf (" nu4 : ");
if (N_AST4_DEFINED (kind_explored)) {
if (N_AST4(node_explored) != (Node)0)
printf ("AST4 %s \n", kind_str(N_KIND(N_AST4(node_explored))));
else
printf ("AST4 (Node)0 \n");
}
else if (N_TYPE_DEFINED (kind_explored))
printf ("Symbol type --> %s \n",
nature_str(NATURE(N_TYPE(node_explored))));
else {
printf ("N_PTYPES ");
if (N_PTYPES (node_explored) != ((Set)0))
display_node_list((Tuple)N_PTYPES(node_explored), list_begin);
else
printf ("empty_set\n");
}
printf ("\n");
}
}
void explorast (Node root) /*;explorast*/
{
explored current;
int next_step;
int list_node;
int list_low;
char answer[10];
current.genre = NODE_GENRE;
current.addr.n = root;
list_low = 1;
do {
if (current.genre == NODE_GENRE)
display_node (current.addr.n, list_low);
else
display_symbol (current.addr.s);
next_step = UNDEFINED_STEP;
list_node = 0;
while (next_step == UNDEFINED_STEP) {
printf (" what shall be the next step ? ");
scanf ("%10s", answer);
next_step = analyze (answer, current, &list_node, &list_low);
}
switch (next_step) {
case 0 :
current = pop ();
break;
case 11:
push (current);
current.genre = NODE_GENRE;
current.addr.n = N_AST1 (current.addr.n);
break;
case 21:
push (current);
current.genre = NODE_GENRE;
current.addr.n = N_AST2 (current.addr.n);
break;